<?php
require_once 'phpFlickr.php';
require_once 'apikey.php';

class IndexController extends Zend_Controller_Action
{
    public function indexAction()
    {
        $this->view->title = "Welcome!";
        
        // TO DO: If logged in, show options, if not show login        
    }
    
    // Handler for receiving Flickr Authentication, storing as an Auth
    // and redirecting to calling page.
    public function flickrauthAction()
    {
        $this->view->title = "Flickr Authentication";
        
        $default_redirect        = "/flickrocd/index/";
        $permissions             = "read";
        $path_to_phpFlickr_class = "./";
        
        unset($_SESSION['phpFlickr_auth_token']);
     
        if (!empty($_GET['extra'])) {
            $redirect = $_GET['extra'];
        }
        
        $f = new phpFlickr(API_KEY, API_SECRET);
        
        if (empty($_GET['frob'])) {
            $f->auth($permissions, false);
        } else {
            $f->auth_getToken($_GET['frob']);
        }

        if (empty($redirect)) {
            header("Location: " . $default_redirect);
        } else {
            header("Location: " . $redirect);
        }
    }
}
?>